import { BusyIndicator } from '../../../../wing/assets/src';
import { ccclass, ccmodifier } from '../decorators';
import { BaseView } from './BaseView';

/**
 * - 作者: DoooReyn
 * - 日期: 2023.10.31
 * - 名称: TouchMask
 * - 描述: 视图-触摸屏蔽层
 */
@ccclass()
@ccmodifier('TouchMask')
export class TouchMask extends BaseView {
    /** 示忙器 */
    private __indicator: BusyIndicator | null;

    protected onLoad(): void {
        super.onLoad();
        this.__indicator = new BusyIndicator();
    }

    protected onDestroy(): void {
        this.__indicator?.clear();
        this.__indicator = null;
    }

    /** 添加一个任务 */
    increase() {
        this.__indicator?.increase();
    }

    /** 删除一个任务 */
    decrease() {
        this.__indicator?.decrease();
    }

    /** 重置繁忙情况 */
    reset() {
        this.__indicator?.reset();
    }

    /** 当前任务数量 */
    get count() {
        return this.__indicator?.count || 0;
    }

    /** 更新繁忙情况 */
    onUpdate() {
        this.__indicator!.busy ? this.show() : this.hide();
    }

    public async enter() {
        this.__indicator?.add(this);
        await this.show();
        this.logger.debug('进入舞台');
    }

    async exit() {
        this.__indicator?.remove(this);
        await this.hide();
        this.logger.debug('退出舞台');
    }
}
